package jp.sourceforge.akjrcp.psp.commands;

import java.io.File;

import jp.sourceforge.akjrcp.psp.PSPIOCommand;
import jp.sourceforge.akjrcp.psp.PSPSyncView;
import jp.sourceforge.akjrcp.util.FileNameUtils;

public class PSPDeleteCommand extends AbstractIOCommand{

	public PSPDeleteCommand(File src){
		setSrcFile(src);
		
	}
	
	public int execCommand() {
		int ret=0;
		if(!getSrcFile().exists()){
			return PSPIOCommand.SRC_NOT_FOUND;
		}
		
		boolean result=getSrcFile().delete();
		
		if(!result){
			ret=PSPIOCommand.SRC_CANT_DELETE;
		}
		
		//do thumb
		File imgFile=new File(FileNameUtils.getChangedExtensionName(getSrcFile(), "jpg",true));
		if(imgFile.exists()){
			boolean imgd=imgFile.delete();
			if(!imgd){
			PSPSyncView.log.warn("image delete faild:+imgFile");	
			}
		}
		
		return ret;
	}
	
	public String toString(){
		String label;
		label="Delete:"+getSrcFile();
		return label;
	}

}
